class Layer {
    constructor(game, width, height, speedModifier, img) {
        this.game = game;
        this.width = width;
        this.height = height;
        this.speedModifier=speedModifier;
        this.speed = this.game.speed * speedModifier;
        this.x = 0;
        this.y = 0;
        this.img = img;
    }
    update() {
        if (this.x < -this.width) this.x = 0;
        else this.x -= (this.game.speed*this.speedModifier);
    }
    draw(context) {
        context.drawImage(this.img, this.x, this.y, this.width, this.height)
        context.drawImage(this.img, this.x+this.width, this.y, this.width, this.height)
    }
}
export class Background {
    constructor(game) {
        this.game = game;
        this.width = 1667;
        this.height = 500;
        this.layerImgs = document.querySelectorAll('img[layer]')
        this.Layers =[];
        this.layerSpeed=[0,0.2,0.4,0.8,1]
        for(let i=0;i<5;i++){
            this.Layers.push( new Layer(this.game, this.width, this.height, this.layerSpeed[i], this.layerImgs[i]))
        }
    }
    update(){
        this.Layers.forEach(layer=>{
            layer.update()
        })
    }
    draw(context){
        this.Layers.forEach(layer=>{
            layer.draw(context)
        })
    }

}